package pers.lance.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.lance.exam.pojo.Base;
import pers.lance.exam.pojo.Item;
import pers.lance.exam.service.ItemService;

import java.util.List;

/**
 * @ Author     ：LILA3
 * @ Date       ：Created in 1:54 PM 7/31/2018
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    ItemService itemService;

    @GetMapping("/list")
    public List<Item> list() {
        return itemService.listItem();
    }

    @PostMapping("/add")
    public Item add(@RequestBody Item base) {
        return itemService.addItem(base);
    }

    @PostMapping("/delete/{id}")
    public Item delete(@PathVariable("id") String id) {
        Item item = new Item();
        item.setId(id);
        itemService.deleteItem(item);
        return itemService.deleteItem(item);
    }

    @GetMapping("/bid/{bid}")
    public List<Item> findByBase(@PathVariable("bid") String bid) {
        Base base = new Base();
        base.setId(bid);
        return itemService.findByBase(base);
    }
}
